/**
 * @param {string} s
 * @return {string}
*/
var sortSentence = function(s) {
  let result = [];
  s = s.split(" ");
  for(let i = 0; i < s.length; i++) {
    result[parseInt(s[i][s[i].length - 1])] = s[i].split("").slice(0, s[i].length - 1).join("");
  }
  return result.join(" ").trim();
};
let s = "is2 sentence4 This1 a3";
console.log(sortSentence(s));
s = "Myself2 Me1 I4 and3";
console.log(sortSentence(s));
